 /**
  ******************************************************************************
  * @file           : mp3_hw.h
  * @version        : v0.1
  * @brief          : Header for mp3_hwx.c file.
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MP3_HW__H__
#define __MP3_HW__H__

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_ll_tim.h"
#include "stm32f1xx_ll_dma.h"
#include "dac.h"
#include "dma.h"
#include "dac.h"
#include "tim.h"
#include "board.h"

/* Exported macro ------------------------------------------------------------*/
#define TIM_MP3_SAMPLE          TIM4
#define TIM_MP3_CHANGE          TIM3

#define DMA_MP3_DATA            DMA2_Channel1
#define DMA_MP3_DATA_CONTROLER  DMA2
#define DMA_MP3_DATA_CHANNEL    LL_DMA_CHANNEL_1


#define TIMER_CLKSRC                (72000000UL)

/* Exported types ------------------------------------------------------------*/
extern DMA_HandleTypeDef hdma_memtomem_dma2_channel1;

/* Exported constants --------------------------------------------------------*/


/* Exported macro ------------------------------------------------------------*/


/* Exported functions prototypes ---------------------------------------------*/
void mp3_hw_init(void);
void mp3_hw_stop(void);

static inline void mp3_hw_pause(void)
{
    LL_TIM_DisableCounter(TIM_MP3_SAMPLE);
}

static inline void mp3_hw_start(void)
{
    LL_TIM_EnableCounter(TIM_MP3_SAMPLE);
}

static inline void setBufferAlignPending(viod)
{
    NVIC_SetPendingIRQ(DMA2_Channel1_IRQn);
}

static inline void disableX2BuffInterrupt(viod)
{
    NVIC_DisableIRQ(DMA2_Channel3_IRQn);
}

static inline void enableX2BuffInterrupt(viod)
{
    NVIC_EnableIRQ(DMA2_Channel3_IRQn);
}


#define ENTER_CRITICAL()    disableX2BuffInterrupt()
#define EXIT_CRITICAL()     EnableX2BuffInterrupt()


void mp3_hw_start();
void mp3_hw_data_DMA(short *srcptr, short *destptr, uint32_t length);

/* Private defines -----------------------------------------------------------*/


#ifdef __cplusplus
}
#endif

#endif /* __MP3_HW__H__ */
